﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CSP.Common.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace CSP.Web.Manager
{
    public partial class QuerySql : CSPMyHome
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(this.UserProvider.UserName!="admin"){
                Response.Redirect("http://www.tongshuya.com");
            }
        }

        protected void Btn_Submit_Click(object sender, EventArgs e)
        {
            if(this.Txt_Sql.Text.Trim()=="")
            {
                return;
            }
            string sql=this.Txt_Sql.Text;
            DataSet ds = new DataSet();
            string conString = ConfigurationManager.ConnectionStrings["CSPContext"].ToString();

            try
            {
                SqlConnection con = new SqlConnection(conString);
                SqlDataAdapter da = new SqlDataAdapter(sql, con);
                da.Fill(ds);
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }

            ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
            this.GV_Info.DataSource = ds;
            this.GV_Info.DataBind();
            
        }
    }
}